<!--
 * @Author       : wfl
 * @LastEditors  : wfl
 * @description  :
 * @updateInfo   :
 * @Date         : 2022-11-23 16:47:08
 * @LastEditTime : 2023-04-20 14:35:50
-->
<script lang="ts" setup name="InitiatorNode">
import Node from '@main/views/approve-workflow/WorkFlow/tree-node/Node.vue'
import { computed } from 'vue'

const props = defineProps({
  config: {
    type: Object,
    default: () => {
      return {}
    }
  }
})

const emits = defineEmits<{
  (e: 'selected'): void
  (e: 'insertNode', val: string): void
  (e: 'delNode', node: any): void
}>()

const content = computed(() => {
  if (props.config.props?.assignedUser?.length > 0) {
    const texts: any[] = []
    props.config.props.assignedUser.forEach(
      (org: { elementName: any; [key: string]: string; }) => {
        const { elementName } = org
        texts.push(elementName)
      }
    )
    return String(texts).replaceAll(',', '、')
  }
  else {
    return '所有人'
  }
})

const handSelected = () => {
  emits('selected')
}
const handInsertNode = (type: string) => {
  emits('insertNode', type)
}
</script>

<template>
  <Node
    title="发起人"
    :is-root="true"
    :content="content"
    placeholder="所有人"
    header-bgc="#409EFF"
    header-icon="ikflow-Icon_zhanghao"
    @selected="handSelected"
    @insertNode="(type: string) => handInsertNode(type)"
  />
</template>
